# import cv2
# import imutils
# from skimage.metrics import structural_similarity
# import os
#
#
# def compare_image(path_image1, path_image2):
#     """
#     :param path_image1: 第一张图片名称
#     :param path_image2: 第二张图片名称
#     :return: 相似度
#     """
#     # cv打开两张图片
#     image_old = cv2.imread(path_image1)
#     image_new = cv2.imread(path_image2)
#     # 图片转灰
#     gray_old = cv2.cvtColor(image_old, cv2.COLOR_BGR2GRAY)
#     gray_new = cv2.cvtColor(image_new, cv2.COLOR_BGR2GRAY)
#     # 调用内部方法，返回截图百分比
#     (score, diff) = structural_similarity(gray_old, gray_new, full=True)
#     # ding_talk(f"{path_image1}的对比结果为:{'%.2f%%' % (score * 100)}")
#     # 发送钉钉
#     log.critical(f"{path_image1}的对比结果为:{'%.2f%%' % (score * 100)}")
#     diff = (diff * 255).astype("uint8")
#     # 找到不同点的轮廓以致于我们可以在被标识为“不同”的区域周围放置矩形
#     thresh = cv2.threshold(diff, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
#     cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
#     cnts = cnts[0] if imutils.is_cv2() else cnts[0]
#     # 找到一系列区域，在区域周围放置矩形
#     for c in cnts:
#         (x, y, w, h) = cv2.boundingRect(c)
#         cv2.rectangle(image_old, (x, y), (x + w, y + h), (0, 255, 0), 2)
#         cv2.rectangle(image_new, (x, y), (x + w, y + h), (0, 255, 0), 2)
#     # 用cv2.imshow 展现最终对比之后的图片， cv2.imwrite 保存最终的结果图片
#     # cv2.imshow("Modified", imageB)
#     if score != 1:
#         diff_pic = path_image1.split("\\")[-1].replace("1", "diff")
#         cv2.imwrite(diff_pic, image_new)
#     return score
#
#
# def compare_result():
#     # 获取所有图片
#     image_list = os.listdir(get_pic_path())
#     image_list1 = []
#     image_list2 = []
#     for i in image_list:
#         # 名称1的图片进入第一个列表，2的进入第二个列表
#         if i.split("_")[1].split(".")[0] == "1":
#             image_list1.append(i)
#         else:
#             image_list2.append(i)
#     if len(image_list1) == len(image_list2):
#         for i in image_list1:
#             for j in image_list2:
#                 # 循环两个列表，如果_前的名称一致，进行图片对比，对比完成后，跳出循环
#                 if i.split("_")[0] == j.split("_")[0]:
#                     compare_image(i, j)
#                     break
#     else:
#         print("图片数量不一致")
#         return None
#
#
# def remove_image():
#     image_list = os.listdir(get_pic_path())
#     # 删除名称为1的图片
#     for i in image_list:
#         if i.split("_")[1].split(".")[0] == "1":
#             os.remove(i)
#     return None
#
#
# def rename_image():
#     image_list = os.listdir(get_pic_path())
#     # 修改名称1的图片，改为2
#     for j in image_list:
#         if j.split("_")[1].split(".")[0] == "2":
#             os.rename(j, j.split("_")[0] + "_1.png")
#     return None
